#!/bin/sh
if [ -d '/usr/local/ddos' ]; then
	echo; echo; echo "Please un-install（ddos_uninstall.sh） the previous version first"
	exit 0
else
	mkdir /usr/local/ddos
fi
clear
echo; echo 'Installing DOS-Deflate 0.6'; echo
echo; echo -n 'Downloading source files...'
wget -q -O /usr/local/ddos/ddos.conf http://www.inetbase.com/scripts/ddos/ddos.conf

echo -e "
现在开始自定义设置："

read -p "每分钟最大连接数,建议设置（次）150：" conn_num
echo -e "\033[41;37m 输入的每分钟最大连接数是：$conn_num \033[0m"
sed -i "s/NO_OF_CONNECTIONS=.*/NO_OF_CONNECTIONS=$conn_num/g" /usr/local/ddos/ddos.conf

read -p "禁用IP时间，建议设置（秒）600：" banperiodnum
echo -e "\033[41;37m 输入的每分钟最大连接数是：$banperiodnum \033[0m"
sed -i "s/BAN_PERIOD=.*/BAN_PERIOD=$banperiodnum/g" /usr/local/ddos/ddos.conf



read -p "请输入被攻击时接受攻击者信息的邮箱地址：" ddde_mailaddr
echo -e "\033[41;37m 输入的邮箱地址是：$ddde_mailaddr \033[0m"
sed -i "s/EMAIL_TO=.*\"/EMAIL_TO=\"$ddde_mailaddr\"/g" /usr/local/ddos/ddos.conf



echo -n '.'
wget -q -O /usr/local/ddos/LICENSE http://www.inetbase.com/scripts/ddos/LICENSE
echo -n '.'
wget -q -O /usr/local/ddos/ignore.ip.list http://www.inetbase.com/scripts/ddos/ignore.ip.list
echo -n '.'
wget -q -O /usr/local/ddos/ddos.sh http://www.inetbase.com/scripts/ddos/ddos.sh
chmod 0755 /usr/local/ddos/ddos.sh
cp -s /usr/local/ddos/ddos.sh /usr/local/sbin/ddos
echo '...done'

echo; echo -n 'Creating cron to run script every minute.....(Default setting)'
/usr/local/ddos/ddos.sh --cron > /dev/null 2>&1
echo '.....done'
echo; echo 'Installation has completed.'
echo 'Config file is at /usr/local/ddos/ddos.conf'
echo
 
echo -e "
+----------------------------------------------------------------------+
|       DDos deflat安装完成！同一IP每分钟建立$conn_num次连接将拉黑$banperiodnum秒，发送提醒邮箱$ddde_mailaddr        |
+----------------------------------------------------------------------+
"
